home *** CD-ROM | disk | FTP | other *** search
- ; by Jeff
-
- ; RawDoFmt
- ; < A0: format string
- ; < A1: datastream
- ; < A2: PutChProc
- ; < A3: PutChData
-
- GETCHAR:MACRO
- move.b (A0)+,D0
- beq.b .storechar
- ENDM
-
-
- RAWDOFMT:
- .loop
- GETCHAR
- cmp.b #'%',D0
- bne.b .storechar
-
- ; special %
-
- GETCHAR
-
- cmp.b #'s',D0
- bne.b .nos
-
- move.l (A1)+,D1 ; string value
-
- bsr .strcpy
- bra.b .loop
- .nos
- ; numeric arg
-
- cmp.b #'l',D0
- bne.b .nolong
- move.l (A1)+,D1 ; longword value
- GETCHAR ; next argument
- bra.b .nextnum
- .nolong
- moveq.l #0,D1
- move.w (A1)+,D1 ; word value
- .nextnum
- cmp.b #'d',D0
- bne.b .nod
-
- move.l D1,D0 ; value
-
- lea -20(A7),A7 ; allocates stack
-
- move.l A7,A1 ; A1: buffer
-
- bsr _HexToDecString
-
- move.l A7,D1
- bsr .strcpy
-
- lea 20(A7),A7 ; deallocates stack
- bra.b .loop
- .nod
- cmp.b '%',D0
- beq.b .storechar ; escaped %% char
-
- ; ERROR, not supported
-
- EMUFAIL _LVORawDoFmt,_execname
-
- .storechar:
- move.l D0,-(A7)
- jsr (a2)
- move.l (A7)+,D0
- tst.b D0
- beq.b .out
- bra.b .loop
- .out
- rts
-
- .strcpy:
- move.l A4,-(a7)
-
- move.l D1,A4
- .strloop:
- move.b (A4)+,D0
- beq.b .strout
- jsr (A2)
- bra.b .strloop
- .strout:
- move.l (A7)+,A4
- rts
-
-
- ; *** "ripped" from JST utils
- ; *** Converts a hex number to a ascii string of the decimal value
- ; < D0: number (-655350:655350), if overflow, Nan or -Nan is returned
- ; < A1: pointer to destination buffer (must be at least of size 8)
- ; out: nothing
-
- _HexToDecString:
- movem.l D0-A6,-(A7)
-
- tst.l D0
- bpl.b .positive
- neg.l D0 ; D0 = -D0
- move.b #'-',(A1)+
- .positive
-
- cmp.l #655351,D0
- bcs.b .ok
-
- ; overflow
-
- move.l A1,A3
- move.b #'N',(A3)+
- move.b #'a',(A3)+
- move.b #'N',(A3)+
- bra .end
- .ok
- move.l A1,A2 ; store user buffer pointer
-
- move.l D0,D2
- moveq.l #0,D3
-
- .loop
- divu #10,D2
- swap D2
- move.w D2,D3 ; D3=remainder
-
- add.b #'0',D3
- move.b D3,(A2)+ ; store the number in reverse
-
- clr.w D2
- swap D2 ; D2=result
- tst.l D2
- bne.b .loop
-
- ; division over, now reverse the number in the buffer
-
- move.l A2,A3 ; store end of string
-
- move.l A2,D0
- sub.l A1,D0 ; D0: number of digits
- lsr #1,D0 ; only swap on half!
- beq.b .end ; 1 char: no swap
- subq.l #1,D0
- .reverse
- move.b -(A2),D2
- move.b (A1),(A2)
- move.b D2,(A1)+
- dbf D0,.reverse
- .end
- clr.b (A3)
-
- movem.l (A7)+,D0-A6
- rts
-